package com.bw.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.bw.finance.eneity.TbUserRole;
import com.bw.finance.mapper.TbUserRoleMapper;
import com.bw.finance.service.ITbUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lizhengqian
 * @since 2020-05-09
 */
@Service
public class TbUserRoleServiceImpl extends ServiceImpl<TbUserRoleMapper, TbUserRole> implements ITbUserRoleService {
    @Autowired
    private TbUserRoleMapper mapper;
    @Override
    public void add(Long userid, Long[] roleIds) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("USER_ID",userid);
        mapper.delete(queryWrapper);
        List<TbUserRole> list=new ArrayList<>();
        for (Long roleid:roleIds) {
            TbUserRole tbUserRole=new TbUserRole();
            tbUserRole.setUserId(userid);
            tbUserRole.setRoleId(roleid);
            list.add(tbUserRole);
        }
        this.saveBatch(list);
    }
}
